package p700;

import java.util.Arrays;

public class Leetcode_747 {
    public int dominantIndex(int[] nums) {
        if (nums.length == 1) {
            return 0;
        }
        int[] t = new int[nums.length];
        System.arraycopy(nums, 0, t, 0, nums.length );
        Arrays.sort(t);
        if (t[t.length - 1] >= t[t.length - 2] * 2) {
            int tt = t[nums.length - 1];
            for (int i = 0; i < nums.length; i++) {
                if (tt == nums[i]) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Leetcode_747 l = new Leetcode_747();
        System.out.println(l.dominantIndex(new int[]{0,0,1,2}));
    }
}
